var newsTable;
function getadShowList() {
    if (typeof newsTable !== 'undefined') {
        newsTable.fnPageChange('first');
        return;
    }
    var i = 1;
    newsTable = $("#adShowList").DataTable({
        "sAjaxSource": _path + "/adShow/queryByPage",          
        "fnServerParams": function (aoData) {
            aoData.push(
                {"name": "name" ,"value":$("#name").val()},
                {"name": "status" ,"value":$("#status").val()},
                { "name": "fromDate", "value": $("#fromDate").val() },
                { "name": "toDate", "value": $("#toDate").val() }
            );
        },
        "sServerMethod": "POST",
        "sAjaxDataProp": "dataList",
        "fnCreatedRow": function () {
            i++;
        },
        "fnPreDrawCallback": function () {
            i = 1;
        },
        "aoColumns": [
            { "sTitle": "序号", "sWidth": "2%",
                "mData": function () {
                    return i;
                }
            },    
            { "sTitle": "id", "mData": "id", "sWidth": "10%" },
            { "sTitle": "广告名称", "mData": "name", "sWidth": "10%" },
            { "sTitle": "开始时间", "mData": "adbegin", "sWidth": "10%" },
            { "sTitle": "结束时间", "mData": "adend", "sWidth": "10%" },
            { "sTitle": "URL源地址", "mData": "urlsource", "sWidth": "10%" },
            { "sTitle": "URL目标地址", "mData": "urltarget", "sWidth": "10%" },
            { "sTitle": "状态", "mData": "status", "sWidth": "10%",
            	"mRender": function (data) {
                    var status = '';
                    switch (data) {
                    	case '0':
                    		status = '已发布';
                    		break;
                    	case '1':
                    		status = '已下架';
                    		break;
                        case '2':
                        	status = '审核中';
                            break;
                        case '3':
                        	status = '审核不通过';
                            break;
                        default :
                        	status = '未知';
                            break;
                    }
                    return status;
                }
            },
            { "sTitle": "记录时间", "mData": "createTime", "sWidth": "10%" },
            { "sTitle": "操作", "sWidth": "10%",
                "mData": function (data) {
                    var status = '<a href="' + _path + '/adShow/edit/' + data.id + '" class="btn default btn-xs purple"><i class="fa fa-edit" title="编辑"></i></a>';
                    status += '<a href="' + _path + '/adShow/del/' + data.id + '"  class="btn default btn-xs red"><i class="fa fa-trash-o" title="删除"></i></a>';
                    return status;
                }
            }
        ]
    });
    

}


